package com.house.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.house.entity.House;
import com.house.mapper.HouseMapper;
import com.house.service.HouseService;
import com.house.util.HouseCondition;
import com.house.util.PageParmeter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HouseServiceImpl implements HouseService {
    @Autowired(required = false)
    private HouseMapper houseMapper;
    @Override
    public int addHouse(House house) {
        return this.houseMapper.insertSelective(house);
    }


    @Override
    public PageInfo<House> getHouseByUser(Integer userid, PageParmeter pageParmeter) {
        PageHelper.startPage(pageParmeter.getPage(),pageParmeter.getPageSize());
        List<House> houseByUser =this.houseMapper.getHouseByUser(userid);
        return new PageInfo<House>(houseByUser);
    }

    @Override
    public int deleteHouse(String id, Integer delState) {
        House house=new House();
        house.setId(id);
        house.setIsdel(delState);
        int i = this.houseMapper.updateByPrimaryKeySelective(house);
        return i;
    }

    @Override   //查询单挑
    public House getHouse(String id) {
        return this.houseMapper.getHouse(id);
    }

    @Override
    public House gestHouse(String id) {
        return this.houseMapper.selectByPrimaryKey(id);
    }



    @Override   //分页带条件
    public PageInfo<House> getBroswerHouse(HouseCondition houseCondition) {
        PageHelper.startPage(houseCondition.getPage(),houseCondition.getPageSize());
        List<House> searchHouse = this.houseMapper.getSearchHouse(houseCondition);
        return new PageInfo<House>(searchHouse);
    }
}
